package leecode

import "math"

type MinStack155 struct {
	stack    []int //栈
	minStack []int //栈顶元素为最小值
}

func Constructor155() MinStack155 {
	minStack := make([]int, 1)
	minStack[0] = math.MaxInt
	return MinStack155{
		stack:    make([]int, 0),
		minStack: minStack,
	}
}

func (this *MinStack155) Push(val int) {
	this.stack = append(this.stack, val)
	top := this.minStack[len(this.minStack)-1]
	this.minStack = append(this.minStack, min(top, val))
}

func (this *MinStack155) Pop() {
	this.stack = this.stack[:len(this.stack)-1]
	this.minStack = this.minStack[:len(this.minStack)-1]
}

func (this *MinStack155) Top() int {
	return this.stack[len(this.stack)-1]
}

func (this *MinStack155) GetMin() int {
	return this.minStack[len(this.minStack)-1]
}
